package com.ds.infrastructure.hyperspace.container.internal.util;

import java.net.InetSocketAddress;
import java.net.SocketAddress;

import static com.ds.infrastructure.hyperspace.container.internal.util.StringConstant.HYPHEN;

/**
 * @Author: yaozh
 * @Description:
 */
public class AddressesUtil {

    private AddressesUtil() {
    }

    public static String getIpAndPort(SocketAddress address) {
        if (address instanceof InetSocketAddress) {
            InetSocketAddress inetSocketAddress = (InetSocketAddress) address;
            if (inetSocketAddress.getAddress() != null) {
                return inetSocketAddress.getAddress().getHostAddress() + ":" + inetSocketAddress.getPort();
            }
            return inetSocketAddress.toString();
        }
        return HYPHEN;
    }
}
